﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace HuaCheng.Controller
{
    public class IndexPageHelper
    {
        /// <summary>
        /// 保存通道数据
        /// </summary>
        /// <param name="chlList"></param>
        /// <param name="path"></param>
        public static void SaveChlParams(List<Channels> chlList, string path)
        {
            IFormatter serializer = new BinaryFormatter();
            FileStream saveFile = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
            serializer.Serialize(saveFile, chlList);//序列化对象集合
            saveFile.Close();
        }
        /// <summary>
        /// 获取通道数据
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static List<Channels> GetChlParams(string path)
        {
            List<Channels> chls = new List<Channels>();
            if (System.IO.File.Exists(path))
            {
                IFormatter serializer = new BinaryFormatter();
                FileStream loadFile = new FileStream(path, FileMode.Open, FileAccess.Read);
                chls = serializer.Deserialize(loadFile) as List<Channels>;//反序列对象集合
            }
            return chls;
        }
    }
}
